#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 1e6 + 10;

int n;
int tr[N][26], ne[N], f[N], idx;
char str[N];
int id[N];
int q[N];

void insert(int x){
    int p = 0;
    for(int i = 0; str[i]; i ++){
        int t = str[i] - 'a';
        if(!tr[p][t]) tr[p][t] = ++ idx;
            f[tr[p][t]] ++;
            p = tr[p][t];
        
    }
    id[x] = p;
}

void build(){
    int hh = 0, tt = -1;
    for(int i = 0; i < 26; i ++){
        if(tr[0][i]) q[++tt] = tr[0][i];
    }

    while(hh <=  tt){
        int p = q[hh++];
        for(int i = 0; i < 26; i ++){
            if(!tr[p][i]){
                tr[p][i] = tr[ne[p]][i];
            }else{
                ne[tr[p][i]] = tr[ne[p]][i];
                q[++tt] = tr[p][i];
            }
        }
    }
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i ++){
        scanf("%s", str);
        insert(i);
    }

    build();

    int res = 0;
    for(int i = idx - 1; i >= 0; i --){
        f[ne[q[i]]] += f[q[i]];
    }

    for (int i = 0; i < n; i ++ ) printf("%d\n", f[id[i]]);

    return 0;
}